const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const dealTime = num =>{     // num：未来天数
  var time = new Date()     // 获取当前时间日期
  var date = new Date(time.setDate(time.getDate() + num)).getDate()  //这里先获取日期，在按需求设置日期，最后获取需要的
  var month = time.getMonth() + 1   // 获取月份
  var day = time.getDay()   //  获取星期
  switch (day) {             //  格式化
    case 0: day = "周日"
      break
    case 1: day = "周一"
      break
    case 2: day = "周二"
      break
    case 3: day = "周三"
      break
    case 4: day = "周四"
      break
    case 5: day = "周五"
      break
    case 6: day = "周六"
      break
  }
  var obj = {
    date: date,
    day: day,
    month: month,
    newday:month + '-' + date
  }
  return obj      // 返回对象
}

module.exports = {
  formatTime: formatTime,
  dealTime:dealTime
}
